package com.chinatsp.onlineapp.presenter;

import org.xutils.http.RequestParams;

import com.chinatsp.onlineapp.base.Config;
import com.chinatsp.onlineapp.bean.ActiveBean;
import com.chinatsp.onlineapp.bean.HostParamsBean;
import com.google.gson.Gson;

import android.content.Context;
import tsp.cn.http.BaseIDao;
import tsp.cn.http.interfac.INetResult;
import tsp.cn.http.tools.LogUtil;
import tsp.cn.http.tools.PreferenceUtils;

public class ActiveDeviceDao extends BaseIDao implements INetResult{
	ActiveBean mActiveBean;
	
	public ActiveDeviceDao(Context context, INetResult iNetResult) {
		super(context, iNetResult);
		// TODO Auto-generated constructor stub
	}

    public ActiveBean getActiveBean(){
    	return mActiveBean;
    }
    
	@Override
	public void onRequestSuccess(String result, int requestCode) {
		// TODO Auto-generated method stub
		mActiveBean = new Gson().fromJson(result, ActiveBean.class);
	}

	

	public void postActive() {
		String ucs_api_host = PreferenceUtils.getPreference("ucs_api_host");
		String factory_code = PreferenceUtils.getPreference("factory_code");
		String SN = PreferenceUtils.getSN();
		
		String url = "http://"+ucs_api_host+"/"+factory_code+"/1.0/sn/"+SN+"/active/";
		
		String customer_key = PreferenceUtils.getCustomeKey();
		String access_token = PreferenceUtils.getAccessTokenPublic();
		
		RequestParams params = new RequestParams(url);
		
		params.setHeader("Cookie", "customer_key="+customer_key+";access_token="+access_token+";");

		postRequest(params, Config.CODE_GET_HOST_ACTIVE);
	}

	@Override
	public void onRequestSuccess(int requestCode) {
		// TODO Auto-generated method stub
		LogUtil.d( "ActiveBean onRequestSuccess");
	}

	@Override
	public void onRequestFailed(String errorNo, String errorMessage) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onFinished() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onNoConnect() {
		// TODO Auto-generated method stub
		
	}
	
}
